package com.dlwx.firefighting.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.dlwx.firefighting.R;
import com.dlwx.firefighting.config.Constant;
import com.dlwx.firefighting.utils.SPUtils;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 余额界面
 */
public class BalanceActivity extends BaseActivity {

    @BindView(R.id.title_left_one_btn)
    ImageView titleLeftOneBtn;
    @BindView(R.id.title_left_one_tv)
    TextView titleLeftOneTv;
    @BindView(R.id.title_left_two_btn)
    ImageView titleLeftTwoBtn;
    @BindView(R.id.title_left_two_tv)
    TextView titleLeftTwoTv;
    @BindView(R.id.tv_middle_title)
    TextView tvMiddleTitle;
    @BindView(R.id.title_right_one_btn)
    ImageView titleRightOneBtn;
    @BindView(R.id.title_right_two_btn)
    ImageView titleRightTwoBtn;
    @BindView(R.id.title_right_one_tv)
    TextView titleRightOneTv;
    @BindView(R.id.title_right_one_tv2)
    TextView titleRightOneTv2;
    @BindView(R.id.tv_money)
    TextView tvMoney;
    @BindView(R.id.tv_today_income)
    TextView tvTodayIncome;
    @BindView(R.id.tv_total_income)
    TextView tvTotalIncome;
    @BindView(R.id.rl_withdraw)
    RelativeLayout rlWithdraw;
    @BindView(R.id.rl_red_package)
    RelativeLayout rlRedPackage;
    @BindView(R.id.rl_trade)
    RelativeLayout rlTrade;
    @BindView(R.id.tv_confirm)
    TextView tvConfirm;
    private String userId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_balance);
        ButterKnife.bind(this);
        userId = (String) SPUtils.get(this, Constant.USER_ID, "");
        initView();
        getDatas();
    }

    private void getDatas() {
        OkGo.<String>post(Constant.BALANCE)
                .tag(this)
                .params("user_id", userId)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
//                        DealResult dealResult = new DealResult();
//                        List<StatusBean> beans = dealResult.deal(BalanceActivity.this, response, new TypeToken<BaseBean<StatusBean>>() {
//                        }.getType());
//                        if (beans.isEmpty()) {
//                            return;
//                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
//                        ToastUtils.toastForShort(AddressSelectActivity.this, getString(R.string.bad_net));
                        super.onError(response);
                    }
                });
    }

    private void initView() {
        titleLeftOneBtn.setVisibility(View.VISIBLE);
        titleRightOneBtn.setVisibility(View.VISIBLE);
        tvMiddleTitle.setText("我的钱包");
        String remind = (String) SPUtils.get(this, Constant.REMIND, "");
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (result != null) {
            if (result.getContents() == null) {
                Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }

    @OnClick({R.id.title_left_one_btn, R.id.rl_withdraw, R.id.rl_red_package, R.id.rl_trade,R.id.tv_confirm})
    public void onViewClicked(View view) {
        Intent i = new Intent(this, WithdrawHisActivity.class);
        switch (view.getId()) {
            case R.id.title_left_one_btn:
                finish();
                break;
            case R.id.rl_withdraw:
                i.putExtra("type", Constant.WITH_DRAW);
                startActivity(i);
                break;
            case R.id.rl_red_package:
                i.putExtra("type", Constant.RED_PACKAGE);
                startActivity(i);
                break;
            case R.id.rl_trade:
                i.putExtra("type", Constant.TRADE);
                startActivity(i);
                break;
            case R.id.tv_confirm:
                startActivity(new Intent(this,WithDrawalActivity.class));
                break;
        }
    }
    //------------------------------------------------------
}
